﻿package mortal.game.view.wizard.panel
{
    import __AS3__.vec.*;
    import com.gengine.global.*;
    import com.gengine.resource.*;
    import com.greensock.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.manager.*;
    import com.mui.utils.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.manager.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.wizard.data.*;

    public class WizardSoulPanel extends GSprite
    {
        private var _wizardData:WizardData;
        private var _soulNum:int;
        private var _lineSprite:GSprite;
        private var _showAttr:GTextFiled;
        private var _nextAttr:GTextFiled;
        private var _soulLists:Vector.<GBitmap>;
        private var _soulSpList:Vector.<ToolTipSprite>;
        private var _soulTxtList:Vector.<GTextFiled>;
        private var _soulPointList:Array;
        private var _isLoad:Boolean;
        private var _currentPoint:Point;
        private var _textText:GTextFiled;
        private var _mc:GSprite;
        private var _bm:GBitmap;
        private var _bd:BitmapData;

        public function WizardSoulPanel()
        {
            this._soulLists = new Vector.<GBitmap>;
            this._soulSpList = new Vector.<ToolTipSprite>;
            this._soulTxtList = new Vector.<GTextFiled>;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._lineSprite = UICompomentPool.getUICompoment(GSprite);
            UIFactory.setObjAttri(this._lineSprite, 0, 0, -1, -1, this);
            var _loc_1:* = GlobalStyle.textFormatChen.center();
            _loc_1.size = 16;
            this._showAttr = UIFactory.gTextField("", 0, 0, 150, 25, null, _loc_1);
            this._nextAttr = UIFactory.gTextField("", 0, 0, 150, 20, null, GlobalStyle.textFormatBai.center());
            LoaderHelp.addResCallBack(ResFileConst.wizardSoulPanel, this.showSkin);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this.name = "";
            this._lineSprite.graphics.clear();
            this._lineSprite.dispose(param1);
            this._lineSprite = null;
            this._showAttr.dispose(param1);
            this._showAttr = null;
            this._nextAttr.dispose(param1);
            this._nextAttr = null;
            if (this._bd)
            {
                this._bd.dispose();
                this._bd = null;
            }
            if (this._mc)
            {
                this._mc.dispose(param1);
                this._mc = null;
            }
            if (this._bm)
            {
                this._bm.dispose(param1);
                this._bm = null;
            }
            this._wizardData = null;
            this._soulLists.length = 0;
            this._soulSpList.length = 0;
            this._soulTxtList.length = 0;
            super.disposeImpl(param1);
            return;
        }// end function

        private function showSkin() : void
        {
            var _loc_2:GBitmap = null;
            var _loc_3:ToolTipSprite = null;
            var _loc_4:GTextFiled = null;
            var _loc_5:int = 0;
            if (this.isDisposed)
            {
                return;
            }
            var _loc_1:int = 10;
            while (_loc_5 < _loc_1)
            {
                
                _loc_3 = UICompomentPool.getUICompoment(ToolTipSprite);
                _loc_3.mouseChildren = false;
                _loc_3.mouseEnabled = true;
                _loc_3.buttonMode = true;
                if (Global.isDebugModle)
                {
                    _loc_3.configEventListener(MouseEvent.MOUSE_DOWN, this.kk);
                    _loc_3.configEventListener(MouseEvent.MOUSE_UP, this.kk2);
                    this._textText = UIFactory.gTextField("", 0, 200, 300, 60, this);
                    this._textText.multiline = true;
                    this._textText.selectable = true;
                    this.pushUIToDisposeVec(this._textText);
                }
                this.addChild(_loc_3);
                _loc_2 = UIFactory.gBitmap("", -13.5, -13.5, _loc_3);
                _loc_4 = UIFactory.gTextField("", -9, -11, 20, 20, _loc_3, GlobalStyle.textFormatBai.center());
                this._soulSpList.push(_loc_3);
                this._soulLists.push(_loc_2);
                this._soulTxtList.push(_loc_4);
                this.pushUIToDisposeVec(_loc_3);
                this.pushUIToDisposeVec(_loc_2);
                this.pushUIToDisposeVec(_loc_4);
                _loc_5++;
            }
            if (!this._isLoad)
            {
                this._isLoad = true;
                this.refreshInfo(false);
            }
            return;
        }// end function

        private function kk(event:MouseEvent) : void
        {
            if (event.shiftKey)
            {
                this._currentPoint = new Point(mouseX, mouseY);
            }
            else
            {
                (event.target as GSprite).startDrag();
            }
            (event.target as GSprite).configEventListener(MouseEvent.MOUSE_MOVE, this.kk3);
            return;
        }// end function

        private function kk2(event:MouseEvent) : void
        {
            var _loc_2:ToolTipSprite = null;
            (event.target as GSprite).stopDrag();
            (event.target as GSprite).removeEventListener(MouseEvent.MOUSE_MOVE, this.kk3);
            this._textText.text = "";
            for each (_loc_2 in this._soulSpList)
            {
                
                this._textText.text = this._textText.text + ("[" + _loc_2.x + "," + _loc_2.y + "],");
            }
            return;
        }// end function

        private function kk3(event:MouseEvent) : void
        {
            var _loc_2:ToolTipSprite = null;
            if (event.shiftKey)
            {
                for each (_loc_2 in this._soulSpList)
                {
                    
                    _loc_2.x = _loc_2.x + (mouseX - this._currentPoint.x);
                    _loc_2.y = _loc_2.y + (mouseY - this._currentPoint.y);
                }
                this._currentPoint.x = mouseX;
                this._currentPoint.y = mouseY;
            }
            this.refreshInfo(false, true);
            return;
        }// end function

        private function getPosition() : Array
        {
            var _loc_5:Point = null;
            var _loc_1:* = this._wizardData.tSprite.mcoordinates;
            _loc_1 = _loc_1.replace(new RegExp(/[\[\]]""[\[\]]/g), "");
            var _loc_2:* = _loc_1.split(",");
            var _loc_3:* = new Array();
            var _loc_4:int = 0;
            while (_loc_4 < _loc_2.length)
            {
                
                _loc_5 = new Point();
                _loc_5.x = _loc_2[_loc_4];
                _loc_5.y = _loc_2[(_loc_4 + 1)];
                _loc_3.push(_loc_5);
                _loc_4 = _loc_4 + 2;
            }
            return _loc_3;
        }// end function

        public function setWizardInfo(param1:WizardData) : void
        {
            var _loc_2:Boolean = false;
            if (this._wizardData == param1)
            {
                _loc_2 = true;
            }
            else
            {
                _loc_2 = false;
            }
            this._wizardData = param1;
            this._soulNum = WizardConfig.instance.vcAttributeName.length;
            this._soulPointList = this.getPosition();
            this.refreshInfo(_loc_2);
            return;
        }// end function

        private function refreshInfo(param1:Boolean = true, param2:Boolean = false) : void
        {
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            if (!this._isLoad)
            {
                return;
            }
            if (this._wizardData == null)
            {
                return;
            }
            this._lineSprite.graphics.clear();
            this._showAttr.text = "";
            this._nextAttr.text = "";
            var _loc_3:* = this._soulLists.length;
            var _loc_4:* = WizardConfig.instance.vcAttributeName;
            while (_loc_5 < _loc_3)
            {
                
                if (_loc_5 < this._soulNum)
                {
                    this._soulLists[_loc_5].filters = [];
                    EffectManager.glowFilterUnReg(this._soulLists[_loc_5]);
                    _loc_6 = 0;
                    if (this._wizardData.isHasWizard)
                    {
                        _loc_6 = this._wizardData.tSprite[_loc_4[_loc_5]];
                    }
                    this._soulSpList[_loc_5].visible = true;
                    if (!this._wizardData.spriteInfo || this._wizardData.spriteInfo.SpriteLevel == 0)
                    {
                        this._lineSprite.graphics.lineStyle(1.5, GlobalStyle.colorHuiUint);
                        this._soulLists[_loc_5].bitmapData = GlobalClass.getBitmapData(ImagesConst.WizardLevelIcon_overSkin);
                        this._soulTxtList[_loc_5].text = "0";
                    }
                    else if (_loc_5 < this._wizardData.spriteInfo.AcupointIndex)
                    {
                        this._lineSprite.graphics.lineStyle(2, this.Color);
                        this._soulLists[_loc_5].bitmapData = GlobalClass.getBitmapData("WizardSoul_" + this._wizardData.code);
                        this._soulTxtList[_loc_5].text = this._wizardData.spriteInfo.SpriteLevel.toString();
                        if (_loc_5 == (this._wizardData.spriteInfo.AcupointIndex - 1) && param1)
                        {
                            this.clickEff(this._soulLists[_loc_5]);
                        }
                    }
                    else if (_loc_5 == this._wizardData.spriteInfo.AcupointIndex)
                    {
                        this._lineSprite.graphics.lineStyle(1.5, GlobalStyle.colorHuiUint);
                        this._soulLists[_loc_5].bitmapData = GlobalClass.getBitmapData(ImagesConst.WizardLevelIcon_overSkin);
                        this._soulTxtList[_loc_5].text = ((this._wizardData.spriteInfo.SpriteLevel - 1)).toString();
                        if (!this._wizardData.spriteInfo.SpriteLevel >= WizardUtil.maxLevel)
                        {
                            EffectManager.glowFilterReg(this._soulLists[_loc_5], null, 1, 20);
                            this._showAttr.x = this._soulPointList[_loc_5].x - 75;
                            this._showAttr.y = this._soulPointList[_loc_5].y + 14;
                            this._showAttr.text = _loc_6 > 0 ? ("[ " + GameDefConfig.instance.getAttributeName2(_loc_4[_loc_5]).replace("  ", "") + "+" + _loc_6 + " ]") : ("");
                        }
                    }
                    else
                    {
                        this._lineSprite.graphics.lineStyle(1.5, GlobalStyle.colorHuiUint);
                        this._soulLists[_loc_5].filters = [FilterConst.colorFilter2];
                        this._soulLists[_loc_5].bitmapData = GlobalClass.getBitmapData(ImagesConst.WizardLevelIcon_overSkin);
                        this._soulTxtList[_loc_5].text = ((this._wizardData.spriteInfo.SpriteLevel - 1)).toString();
                    }
                    if (param2 == false)
                    {
                        this._soulSpList[_loc_5].x = this._soulPointList[_loc_5].x;
                        this._soulSpList[_loc_5].y = this._soulPointList[_loc_5].y;
                    }
                    _loc_6 = _loc_6 > 0 ? (_loc_6) : (this._wizardData.tSprite[_loc_4[_loc_5]]);
                    if (_loc_5 > 0)
                    {
                        this._lineSprite.graphics.moveTo(this._soulSpList[(_loc_5 - 1)].x, this._soulSpList[(_loc_5 - 1)].y);
                        this._lineSprite.graphics.lineTo(this._soulSpList[_loc_5].x, this._soulSpList[_loc_5].y);
                        this._lineSprite.graphics.endFill();
                    }
                }
                else
                {
                    this._soulSpList[_loc_5].visible = false;
                    this._showAttr.text = "";
                    this._nextAttr.text = "";
                }
                _loc_5++;
            }
            return;
        }// end function

        private function get Color() : int
        {
            var _loc_1:int = 0;
            switch(this._wizardData.code)
            {
                case 1:
                {
                    _loc_1 = GlobalStyle.colorLvUint;
                    break;
                }
                case 2:
                {
                    _loc_1 = GlobalStyle.colorHuangUint;
                    break;
                }
                case 3:
                {
                    _loc_1 = GlobalStyle.colorZiUint;
                    break;
                }
                case 4:
                {
                    _loc_1 = GlobalStyle.colorHongUint;
                    break;
                }
                case 5:
                {
                    _loc_1 = GlobalStyle.colorDanLanUint;
                    break;
                }
                case 6:
                {
                    _loc_1 = GlobalStyle.colorLvUint;
                    break;
                }
                case 7:
                {
                    _loc_1 = GlobalStyle.colorChenUint;
                    break;
                }
                case 8:
                {
                    _loc_1 = GlobalStyle.colorLanUint;
                    break;
                }
                default:
                {
                    break;
                }
            }
            return _loc_1;
        }// end function

        private function clickEff(param1:DisplayObject, param2:String = "CENTER") : void
        {
            var _loc_3:* = param1.localToGlobal(new Point());
            var _loc_4:* = param1.x;
            var _loc_5:* = param1.y;
            if (this._mc == null)
            {
                this._mc = UICompomentPool.getUICompoment(GSprite);
            }
            if (this._bm == null)
            {
                this._bm = UICompomentPool.getUICompoment(GBitmap);
            }
            if (this._bd == null)
            {
                this._bd = new BitmapData(param1.width, param1.height, true, 255);
            }
            if (param2 == "TOP_LEFT")
            {
                this._bd.draw(param1);
                this._bm.bitmapData = this._bd;
                this._bm.x = (-this._bm.width) / 2;
                this._bm.y = (-this._bm.height) / 2;
                this._mc.x = _loc_4 + this._bm.width / 2;
                this._mc.y = _loc_5 + this._bm.height / 2;
            }
            else
            {
                this._bd.draw(param1);
                this._bm.bitmapData = this._bd;
                this._bm.x = (-this._bm.width) / 2;
                this._bm.y = (-this._bm.height) / 2;
                this._mc.x = _loc_4 + this._bm.width / 2;
                this._mc.y = _loc_5 + this._bm.height / 2;
            }
            this._mc.addChild(this._bm);
            param1.parent.addChild(this._mc);
            this._mc.mouseEnabled = false;
            this._mc.mouseChildren = false;
            TweenLite.to(this._mc, 0.5, {scaleX:3.5, scaleY:3.5, alpha:0, onComplete:this.remove});
            return;
        }// end function

        private function remove() : void
        {
            if (this._bm)
            {
                this._bm.dispose(true);
                this._bm = null;
            }
            if (this._mc)
            {
                this._mc.dispose(true);
                this._mc = null;
            }
            if (this._bd)
            {
                this._bd.dispose();
                this._bd = null;
            }
            return;
        }// end function

    }
}
